<template >
  <div>
    <el-row  v-show="false">
      <a-col :span="15">
        <a-card class="card-design">
          <div id="hiprint-printTemplate" class="hiprint-printTemplate"></div>
        </a-card>
      </a-col>
      <a-col :span="5" class="params_setting_container">
        <a-card>
          <a-row class="hinnn-layout-sider">
            <div id="PrintElementOptionSetting"></div>
          </a-row>
        </a-card>
      </a-col>
    </el-row>
    <!-- 预览 -->
    <print-preview ref="preView"/>
  </div>
</template>
<script>
  import {defaultElementTypeProvider, hiprint} from '@/hiprint/index'
  import printPreview from './preview'
  export default {
    components: {printPreview},
    data() {
        return {
          hiprintTemplate: null,
        }
    },
    props: {
      print: {
          type: Object,
          default: 0,
          require: true
      }
    },
    created(){
      this.init();
    },
    methods: {
      init() {
        hiprint.init({
          providers: [new defaultElementTypeProvider()]
        });
       /*Obfuscated by*/hiprint['setConfig']();hiprint['setConfig']({'optionItems':[(function(){function _0x67369(){this['name']='scale';}return _0x67369['prototype']['css']=function(_0xc155fd,_0x1ef3e6){if(_0xc155fd&&_0xc155fd['length']){if(_0x1ef3e6)return _0xc155fd['css']('transform','scale('+_0x1ef3e6+')');}return null;},_0x67369['prototype']['createTarget']=function(_0x44392f,_0x464052,_0x4527d9){return this['target']=$('<div\x20class=\x22hiprint-option-item\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22hiprint-option-item-label\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20缩放\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22hiprint-option-item-field\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<input\x20type=\x22number\x22\x20class=\x22auto-submit\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20</div>'),this['target'];},_0x67369['prototype']['getValue']=function(){var _0x2bd49d=this['target']['find']('input')['val']();if(_0x2bd49d)return parseFloat(_0x2bd49d['toString']());},_0x67369['prototype']['setValue']=function(_0x2ae00d){this['target']['find']('input')['val'](_0x2ae00d);},_0x67369['prototype']['destroy']=function(){this['target']['remove']();},_0x67369;}()),(function(){function _0x590793(){this['name']='zIndex';}return _0x590793['prototype']['css']=function(_0x32d6be,_0x2dab87){if(_0x32d6be&&_0x32d6be['length']){if(_0x2dab87)return _0x32d6be['css']('z-index',_0x2dab87);}return null;},_0x590793['prototype']['createTarget']=function(){return this['target']=$('<div\x20class=\x22hiprint-option-item\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22hiprint-option-item-label\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20元素层级2\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22hiprint-option-item-field\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<input\x20type=\x22number\x22\x20class=\x22auto-submit\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20</div>'),this['target'];},_0x590793['prototype']['getValue']=function(){var _0x3163f0=this['target']['find']('input')['val']();if(_0x3163f0)return parseInt(_0x3163f0['toString']());},_0x590793['prototype']['setValue']=function(_0x334a72){this['target']['find']('input')['val'](_0x334a72);},_0x590793['prototype']['destroy']=function(){this['target']['remove']();},_0x590793;}())],'movingDistance':2.5,'text':{'tabs':[{'name':'样式','options':[{'name':'scale','after':'transform','hidden':![]}]}],'supportOptions':[{'name':'styler','hidden':!![]},{'name':'scale','after':'transform','hidden':![]},{'name':'formatter','hidden':!![]}]},'image':{'tabs':[{'replace':!![],'name':'基本','options':[{'name':'field','hidden':![]},{'name':'src','hidden':![]},{'name':'fit','hidden':![]}]}]}});hiprint['PrintElementTypeManager']['buildByHtml']($('.ep-draggable-item'));$('#hiprint-printTemplate')['empty']();let that=this;let panel=JSON['parse'](this['print']['panels']['replace']('\x27',''));this['hiprintTemplate']=new hiprint['PrintTemplate']({'template':panel,'onImageChooseClick':_0x412597=>{setTimeout(()=>{_0x412597['refresh']('',{'real':!![]});},0xcb77e^0xcbcc6);},'fontList':[{'title':'微软雅黑','value':'Microsoft\x20YaHei'},{'title':'黑体','value':'STHeitiSC-Light'},{'title':'思源黑体','value':'SourceHanSansCN-Normal'},{'title':'王羲之书法体','value':'王羲之书法体'},{'title':'宋体','value':'SimSun'},{'title':'华为楷体','value':'STKaiti'},{'title':'cursive','value':'cursive'}],'dataMode':0x1,'history':!![],'onDataChanged':(_0x4abf78,_0x1889c7)=>{},'onUpdateError':_0x356b64=>{console['log'](_0x356b64);},'settingContainer':'#PrintElementOptionSetting','paginationContainer':'.hiprint-printPagination'});this['hiprintTemplate']['design']('#hiprint-printTemplate');this['scaleValue']=this['hiprintTemplate']['editingPanel']['scale']||0x9fbb4^0x9fbb5;
        if(this.print.type == 0){
          this.onlyPrint(panel);
        }
        if(this.print.type == 1){
          this.$nextTick(() => {
            this.preView();
          })
        }
        if(this.print.type == 2){
          this.directPrint(panel);
        }
        if(this.print.type == 3){
          this.batchPrint(this.print.num,panel);
        }
      },
      onlyPrint(panel) {
        this.$print(undefined, panel, this.print.getObject, {}, {
            styleHandler: () => {
              let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
              return css
            }
          })
      },
      preView() {
        this.$refs.preView.show(this.hiprintTemplate, this.print.getObject);
      },
      directPrint(panel){
        if (window.hiwebSocket.opened) {
          const printerList = this.hiprintTemplate.getPrinterList();
          console.log(printerList)
          this.$print2(undefined, panel, this.print.getObject, {}, {});
          return
        }
        this.$message.error('客户端未连接,无法直接打印 , 如未下载客户端请到打印模板管理下载')
      },
      batchPrint(num , panel){
        if(num <= 0){
          num = 1;
        }
        let batchData = [];
        for(let i = 0;i < num; i++){
          batchData.push(this.print.getObject);
        }
        this.$print(undefined, panel, batchData, {}, {})
      }
    }
  }
</script>
